<?php
namespace Anls\Controller;
use Think\Controller;
use Anls\Com\File;
use Anls\Com\Bar;
use Anls\Com\Strategy;
use Anls\Common;
use Anls\Common\Log;
/**
 * 模拟交易
 * @author wsf
 *
 */
class AnlsController extends AbstractTradeSupportController{
    
    /**
     * 数据分析入口
     */
    function exec(){
        // 品种
        $symbolType = I('symbolType','stock');
        // 周期
        $period = I('period','1day');
        $highWinLt = I('highWinLt','5%');
        $closeWinLt = I('closeWinLt','0%');
      
        Log::info('品种：'.$symbolType.'，周期：'.$period.'，最高盈利小于：'.$highWinLt.'，平仓盈利小于：'.$closeWinLt);
		
        // 指定代码
        $code = I('code');
        
        Log::info('开始统计分析....');
        // 获取分析文件
        //$fileList = File\FileHandle::getFiles($symbolType,$period);
        //$codeList = $this->redis->lRange('trade:code', 0, -1);
        $codeList = $this->redis->zRange(Common\Redis::$TRADE_CODE_KEY,0,-1);
        $codeListCnt = count($codeList);
   		Log::info('分析个数：'.$codeListCnt.'，key值：'.Common\Redis::$TRADE_CODE_KEY);
        // 获取过滤代码
        $filterCodes = $this->getFilterCodes();
        Log::info('过滤个数：'.count($filterCodes));
        /*
        for($fi=0;$fi<$codeListCnt;$fi++){
        	$code = $codeList[$fi];
        	$this->redis->zAdd('trade:codes',$code,$code);
        }
        */
        $BarH = new Bar\BarHandle();
       
        $DataAnls = new Strategy\DataAnls();
        $DataAnls->setHighWinLt($highWinLt);
        $DataAnls->setCloseWinLt($closeWinLt);
        
        for($fi=0;$fi<$codeListCnt;$fi++){
            // 获取文件名
            $fileName = $codeList[$fi];
            if($code != null){
                if($code != $fileName){
                    continue;
                }
            } else {
                //if($filterCodes[$fileName] == 1) continue;
            }
            
            // 过滤
            $DataAnls->exec($fileName);
            if($code != null && $code == $fileName){
                break;
            }
        }
        Log::info('分析完成！');
    }

}